package com.hxkj.controller;

import com.hxkj.domain.po.AuthFunction;
import com.hxkj.service.FunctionService;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.Callable;

/**
 * @author Mrmas
 * @create 2018-05-21 16:38
 * @desc 功能列表控制器
 **/
@RestController
@RequestMapping(value = "/function")
public class FunctionController {
    private static final Logger LOGGER = LoggerFactory.getLogger(FunctionController.class);

    @Autowired
    private FunctionService functionService;

    /**
     * 获取功能列表
     *
     * @param parameterDataStruct 功能列表
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist",consumes  ="application/json;charset=UTF-8")
    public  ResultPageStruct  getFunctionList(@RequestBody ParameterDataStruct<AuthFunction> parameterDataStruct) throws Exception {
        ResultPageStruct functiontrees = functionService.getFunctionList(parameterDataStruct.getData() == null
                ? new AuthFunction() : parameterDataStruct.getData(), parameterDataStruct.getPageTo());
        return functiontrees;
    }

    /**
     * 新增功能列表
     *
     * @param site 站点信息
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> saveAuthFunction(@RequestBody AuthFunction authFunction) throws Exception {
        return () -> functionService.saveAuthFunction(authFunction);
    }

    /**
     * 更新功能列表
     *
     * @param site 站点信息
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> updateAuthFunction(@RequestBody AuthFunction authFunction) throws Exception {
        return () -> functionService.updateAuthFunction(authFunction);
    }

    /**
     * 获取功能单个信息
     * @param authFunction
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultDataStruct> queryAuthFunction(@RequestBody AuthFunction authFunction) throws Exception{
        return  () -> functionService.queryAuthFunction(authFunction);
    }


    /**
     * 更新功能列表
     *
     * @param site 站点信息
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> deleteAuthFunction(@RequestBody AuthFunction authFunction) throws Exception {
        return () -> functionService.deleteAuthFunction(authFunction);
    }


    /**
     * 更新排序
     *
     * @param site 站点信息
     * @throws Exception
     */
    @RequestMapping(value = "/modifyOrderId", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> modifyOrderId(@RequestBody Map<String,Object> map) throws Exception {
        return () -> functionService.modifyOrderId(map);
    }
}
